package com.example.demo.controller;

import com.example.demo.domain.Person;
import lombok.RequiredArgsConstructor;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.ContextValue;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@SchemaMapping(typeName = "Demo2Query")
@RequiredArgsConstructor
public class Demo2QueryController {

  @QueryMapping
  public Map<String, Object> demo2() {
    return new HashMap() {
      {
        put("name", "sdsdfsd");
      }
    };
  }

  @SchemaMapping
  public Person person(@Argument("input") Person person) {
    return person;
  }

  @SchemaMapping
  public List<Person> persons(@Argument Person person) {
    return Arrays.asList(person, person);
  }

  @SchemaMapping
  public String sayHello(@Argument String name) {
    return String.format("hello %s", name);
  }
}
